<template>
  <div class="second-custom">
    <custom-page :content="detailsList"></custom-page>
    <div class="nodata" v-if="nodata">
      <div class="align-c" style="padding-top: 80px">
        <img v-if="fileSpace" :src="fileSpace + '/images/anchor-nodata.png'" class="width-205 height-173" alt="">
        <div class="align-c mar-t-5 font-16 font-color-9">
          暂无数据
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import CustomPage from '@/components/CustomPage/index'
import { getCustomPage } from '@/api/home'
export default {
  components: { CustomPage },
  data() {
    return {
      detailsList: [],
      nodata: false,
      resData: {}
    }
  },
  mounted() {
    // 设置同个自定义页面，多次进入，存储每次自定义页面ID
    let getSecondPageID = this.$pt.getStorageSync('secondPage') ? this.$pt.getStorageSync('secondPage') : []
    let pageId = this.getCurrentPage().query.pageId
    getSecondPageID.push(pageId)
    this.$pt.setStorageSync('secondPage', getSecondPageID)
    if (this.getCurrentPage().query.pageId) {
      this.pageId = this.getCurrentPage().query.pageId
    }
    this.getCustomPage()
  },
  onShow() {
    this.resData = {}
  },
  onUnload() {
    // 同个自定义页面，多次进入，当返回上个页面时，获取自定义页面ID，并存储
    // let getSecondPageID = this.$pt.getStorageSync('secondPage')
    // if (getSecondPageID.length > 1) {
    //   this.resData = {}
    //   this.detailsList = []
    //   let len = getSecondPageID.length - 1
    //   getSecondPageID.splice(len, 1)
    //   this.$pt.setStorageSync('secondPage', getSecondPageID)
    //   this.pageId = getSecondPageID[getSecondPageID.length - 1]
    //   this.getCustomPage()
    // }
  },
  methods: {
    getCustomPage() {
      this.resData = {}
      this.detailsList = []
      let params = {
        pageId: this.pageId,
        memberId: this.getMemberId,
        customerId: this.getCustomerId,
        enterpriseId: this.getEnterpriseId ? this.getEnterpriseId : '',
        roleType: this.getRoleType ? this.getRoleType : ''
      }
      // if (!this.getCustomerId) return
      getCustomPage(params).then(response => {
        if (response.isError) return
        this.resData = response.data
        this.detailsList = response.data.detailsList
        this.detailsList.forEach(item => {
          if (item.componentType === 12 && item.pictureList && item.pictureList.length && !this.$pt.getStorageSync('iOS')) {
            let that = this
            wx.getImageInfo({
              src: item.pictureList[0].imgUrl,
              success(e) {
                if (item.propMap.picStyle === '10' && !that.$pt.getStorageSync('iOS')) {
                  item.pictureList[0].height = ((that.$pt.getStorageSync('devW') * e.height) / e.width) - item.propMap.verticalMargin * 1
                  item.propMap.pictureHeight = item.pictureList[0].height
                  const changeData = item.pictureList[0].height
                  that.$delete(item.pictureList[0], 'height')
                  that.$set(item.pictureList[0], 'height', changeData)
                  const changeDataPic = item.propMap.pictureHeight
                  that.$delete(item.propMap, 'pictureHeight')
                  that.$set(item.propMap, 'pictureHeight', changeDataPic)
                }
                if (item.propMap.picStyle !== '10' && !that.$pt.getStorageSync('iOS')) {
                  item.pictureList[0].height = ((that.$pt.getStorageSync('devW') / 2 * e.height) / e.width) - item.propMap.verticalMargin * 1
                  item.propMap.pictureHeight = item.pictureList[0].height
                  const changeData = item.pictureList[0].height
                  that.$delete(item.pictureList[0], 'height')
                  that.$set(item.pictureList[0], 'height', changeData)
                  const changeDataPic = item.propMap.pictureHeight
                  that.$delete(item.propMap, 'pictureHeight')
                  that.$set(item.propMap, 'pictureHeight', changeDataPic)
                }
              }
            })
          }
          if (item.componentType === 19 && item.swiperList && item.swiperList.length) {
            let that = this
            wx.getImageInfo({
              src: item.swiperList[0].imgUrl,
              success(e) {
                if (item.propMap.swiperStyle === '10') {
                  item.swiperList[0].height = ((that.$pt.getStorageSync('devW') * e.height) / e.width) - item.propMap.verticalMargin * 1
                  item.propMap.swiperHeight = item.swiperList[0].height
                  const changeData = item.swiperList[0].height
                  that.$delete(item.swiperList[0], 'height')
                  that.$set(item.swiperList[0], 'height', changeData)
                  const changeDataPic = item.propMap.swiperHeight
                  that.$delete(item.propMap, 'swiperHeight')
                  that.$set(item.propMap, 'swiperHeight', changeDataPic)
                }
                if (item.propMap.swiperStyle !== '10') {
                  item.swiperList[0].height = ((that.$pt.getStorageSync('devW') / 2 * e.height) / e.width) - item.propMap.verticalMargin * 1
                  item.propMap.swiperHeight = item.swiperList[0].height
                  const changeData = item.swiperList[0].height
                  that.$delete(item.swiperList[0], 'height')
                  that.$set(item.swiperList[0], 'height', changeData)
                  const changeDataPic = item.propMap.swiperHeight
                  that.$delete(item.propMap, 'swiperHeight')
                  that.$set(item.propMap, 'swiperHeight', changeDataPic)
                }
              }
            })
          }
        })
        setTimeout(() => {
          this.$pt.hideToast()
          // 设置页面标题
          this.$pt.setNavigationBarTitle({
            title: this.resData.mpPageTitle ? this.resData.mpPageTitle : ''
          })
          if (this.resData.titleType === 10) {
            this.$pt.setNavigationBarColor({
              frontColor: '#ffffff',
              backgroundColor: this.resData.titleBackgroundColor ? this.resData.titleBackgroundColor : ''
            })
          } else {
            this.$pt.setNavigationBarColor({
              frontColor: '#000000',
              backgroundColor: this.resData.titleBackgroundColor ? this.resData.titleBackgroundColor : ''
            })
          }
        }, 600)
      })
    }
  }
}
</script>
<style lang="less" scoped>
.container{
  background: #fff;
  min-height: 100vh;
}
</style>
